from django.db import models

# Create your models here.
class Admin(models.Model):
    name = models.CharField(max_length=50)
    password = models.CharField(max_length=50)

    class Meta:
        db_table = 'htadmin'
        verbose_name = '管理员'


class Resource(models.Model):
    name = models.CharField('资源名称', max_length=50)
    pid = models.ForeignKey('self', verbose_name='父级资源',on_delete=models.CASCADE,null=True, blank=True)
    url = models.CharField('访问路径', max_length=200, null=True, blank=True)

    class Meta:
        db_table = 'htresource'
        verbose_name = '资源'

class Role(models.Model):
    name = models.CharField('角色名称', max_length=20, unique=True)
    class Meta:
        db_table = 'htrole'
        verbose_name = '角色'

class AdminRole(models.Model):
    admin = models.ForeignKey('Admin', verbose_name='管理员',on_delete=models.CASCADE)
    role = models.ForeignKey('Role', verbose_name='角色',on_delete=models.CASCADE)
    class Meta:
        db_table = 'htadmin_role'
        verbose_name = '管理员角色'

class RoleResource(models.Model):
    role = models.ForeignKey('Role', verbose_name='角色',on_delete=models.CASCADE)
    resource = models.ForeignKey('Resource', verbose_name='资源',on_delete=models.CASCADE)
    class Meta:
        db_table = 'htrole_resource'
        verbose_name = '角色资源'